fix: wait for background goroutines during shutdown#1756
Conversation
The UI server ignored the shutdown signal and had no way to stop: it used the package-level http.ListenAndServe, which offers no Shutdown. Build a dedicated http.Server on a local mux, watch the context, and drain requests within the grace period. The local mux also keeps routes registered by other packages off the UI port. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The dist folder is gitignored except for a placeholder, so in CI the embedded assets are empty and ServeUI exits before listening. Skip the shutdown test in that case, matching the condition ServeUI itself checks. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Coverage Report for CI Build 29364880379Coverage decreased (-0.02%) to 44.843%Details
Uncovered Changes
Coverage Regressions89 previously-covered lines in 3 files lost coverage.
Coverage Stats
💛 - Coveralls |
rohilsurana
left a comment
There was a problem hiding this comment.
Verified the whole chain: the listener returns ctx.Err() on cancel, #1747's ServeUI returns on every path, and ServeConnect's drain is bounded, so g.Wait() cannot hang for more than the grace period. One suggestion inline about signal handling during that window.
A second SIGINT/SIGTERM during the drain was swallowed by the NotifyContext registration, leaving no way to force-quit a stuck shutdown. Unregister the handler when shutdown begins so the second signal gets default handling. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Based on #1747 — merge that first; this base retargets to main after.
Summary
StartServernow waits for the UI server and the audit log listener tofinish shutting down before running deferred cleanup, instead of only
waiting for the connect server.
Changes
errgroup;StartServerreturnsg.Wait(), so deferred cleanup(database and service
Close()calls) runs only after all threefinish.
failure also winds down the UI server and listener.
normal shutdown.
Technical Details
errgroup.WithContextcancels the group context when any memberreturns an error. Only
ServeConnectreturns a non-nil error, sog.Wait()returns exactly whatStartServerreturned before.Test Plan
go build,go vet,golangci-lintclean"cleaning up" line, with no listener warning
StartServerneeds live Postgres and SpiceDB beforereaching this code; the composed pieces are tested in fix: wait for HTTP server drain during graceful shutdown #1745 and fix: add graceful shutdown to UI server #1747
🤖 Generated with Claude Code